package com.iyunsir.lesson03;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class TestKeyListener {
    public static void main(String[] args) {
        new KeyFrame();
    }

}

class KeyFrame extends Frame{
    public KeyFrame(){
        setBounds(1,2,300,400);
        setVisible(true);

        this.addKeyListener(new KeyAdapter() {

            //键盘按下
            @Override

            public void keyPressed(KeyEvent e){
                //获得键盘下的键是哪一个,当前的码
                int KeyCode = e.getKeyCode(); //不需要去记录这个数值，直接试用静态属性 VK_XXX
                System.out.println(KeyCode);
                if (KeyCode == KeyEvent.VK_UP){
                    System.out.println("你按下了上键");
                }

            }

        });
    }
}
